|
|
|
|
|
|
|
Examples Filename: Employee2.frm |
|
|
|
|
|
|
|
|
When the user clicks the Save button, you apply the Update method to the Recordset object of the data control. This method causes a couple events to occur prior to the data being committed to the database. You have the option of stopping the commit from taking place by setting a parameter in one of these events to a certain value. The event that youll learn about now is called WillChangeRecord. This event fires just before the record is about to be changed. The first parameter passed to this event, called adReason, tells you the reason why this event is being called. In this case, its because the Update method was invoked. It will also pass in an adStatus parameter that you can set to a particular constant to stop the update from happening. |
|
|
|
|
| 1. Type in the WillChangeRecord event, as shown here, for the Employee data control: | | Private Sub datEmployees_WillChangeRecord(_
ByVal adReason As ADODB.EventReasonEnum, _
ByVal cRecords As Long, _
adStatus As ADODB.EventStatusEnum, _
ByVal pRecordset As ADODB.Recordset)
Dim strErr As String
Debug.Print "WillChangeRecord"
If Not datEmployees.Recordset.EOF And _
Not datEmployees.Recordset.BOF Then
If Trim$(txtFirst.Text) = "" Then
strErr = strErr & _
"First Name must be filled in" & vbCrLf
End If
If Trim$(txtLast.Text) = "" Then
strErr = strErr & _
"Last Name must be filled in" & vbCrLf
End If
If Trim$(txtBirthDate.Text) <> "" Then
If Not IsDate(txtBirthDate.Text) Then
strErr = strErr & _
"Birth Date is not a valid date" & vbCrLf
End If
End If |
|
|
|